package cn.edu.scnu.service;

import cn.edu.scnu.entity.Staff;
import cn.edu.scnu.mapper.StaffMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class StaffService extends ServiceImpl<StaffMapper, Staff> {

    @Autowired
    private StaffMapper staffMapper;

    // 获取电影导演姓名
    public List<String> getDirectorsByMovieId(Integer movieId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("movie_id", movieId);
        queryWrapper.eq("staff_role", 1);
        List<Staff> staffList = staffMapper.selectList(queryWrapper);
        List<String> directors = new ArrayList<>();
        for (Staff staff : staffList) {
            directors.add(staff.getStaffName());
        }
        return directors;
    }

    // 获取电影演员姓名
    public List<String> getActorsByMovieId(Integer movieId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("movie_id", movieId);
        queryWrapper.eq("staff_role", 2);
        List<Staff> staffList = staffMapper.selectList(queryWrapper);
        List<String> actors = new ArrayList<>();
        for (Staff staff : staffList) {
            actors.add(staff.getStaffName());
        }
        return actors;
    }
}
